package com.lovo.ssc.controller;

import com.lovo.ssc.entity.SysUser;
import com.lovo.ssc.service.ISysUserService;
import com.lovo.ssc.util.SscsysToKen;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.support.HttpRequestHandlerServlet;

/**
 * <p>
 * 登录用户表 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/user")
@Api(tags = "后台用户模块刘芬")
public class SysUserController {
    @Autowired
    ISysUserService service;

    @ApiOperation("注册")
    @GetMapping("register/{name}/{pwd}/{grade}/{trueName}")
    public String register(@PathVariable("name") String name,
                           @PathVariable("pwd") String pwd,
                           @PathVariable("grade") String grade,
                           @PathVariable("trueName") String trueName) {

        SysUser nameUser = service.findByName(name);
        if (nameUser != null){
            return "no";
        }
        SysUser user = new SysUser();
        user.setName(name);
        user.setPwd(pwd);
        user.setGrade(grade);
        user.setTrueName(trueName);
        service.save(user);
        return "ok";
    }

    @ApiOperation("登录")
    @GetMapping("login/{userName}/{pwd}/{grade}")
    public SysUser login(@PathVariable("userName") String userName,
                         @PathVariable("pwd") String pwd,
                         @PathVariable("grade") String grade){

        return service.login(userName,pwd,grade);
    }

    @ApiOperation("获取token")
    @PostMapping("verifierPsc/{ToKen}")
    public SysUser verifierPsc(@PathVariable("ToKen") String ToKen){
        return SscsysToKen.verifierJwt(ToKen);
    }

}
